<template>
  <div
    ref="echartsRef"
    class="base-echarts"
    :style="{ width: width, height: height }"
  ></div>
</template>

<script lang="ts" setup>
import type { EChartsOption } from 'echarts'

import useEcharts from './useCharts'

// 定义props
interface IProps {
  options: EChartsOption
  width?: string
  height?: string
}
const props = withDefaults(defineProps<IProps>(), {
  width: '100%',
  height: '360px'
})

const echartsRef = ref<HTMLElement>()

onMounted(() => {
  const { setOptions } = useEcharts(echartsRef.value!)
  // option的data数据设为响应式，当data改变这里会重新设置option，即重新渲染
  watchEffect(() => {
    setOptions(props.options)
  })
})
</script>

<style scoped></style>
